// 获取数据
function render() {
  $.ajax({
    url: 'http://192.168.151.94:8888/api/articles/1/comments',
    data: { pagenum: 1, pagesize: 10 },
    success: function (res) {
      console.log(res);
      if (res.status === 0) {
        let str = ''
        res.data.forEach((item) => {
          str += `
          <div class="kr_comment_card">
            <div class="img-wrap">
              <img src="./uploads/avatar_3.jpg" alt="">
            </div>
            <div class="info">
              <p>${item.uname}<span>${item.cdate}</span></p>
              <p>${item.content}</p>
            </div>
            <a href="javascript:;" class="like">${item.count}</a>
          </div>
          `
        })
        // console.log(str)
        $('#publish').html(str)
      }
    }
  })
}
render()

// 点击发布
$('#btn').on('click', function () {
  let btn = $('#id_name').val()
  let tex = $('#id_text').val()

  if (btn === '' || tex === '') {
    alert('值都不能为空');
    return;
  }

  $.ajax({
    type: 'POST',
    url: 'http://192.168.151.94:8888/api/articles/1/comments',
    data: { uname: btn, content: tex },
    success: function (res) {
      console.log(res)
      if (res.status === 0) {
        render()
      }
    }
  })
  $('#id_name').val('')
  $('#id_text').val('')
})